<?php
class DatabaseManager {
protected $database;

function __construct(){
    $this->connect();
}

protected function connect() {
    $this->database = mysqli_connect("192.168.1.20", "group5", "grp5@leg", "group5") or die ("Unable to connect!");
    if(mysqli_connect_errno()){
				printf("Connect failed: %s\n",mysqli_connect_errno());
				exit();
	}
}

function __destruct(){
    mysqli_close($this->database);
}

function getDB(){
     if (!isset($this->database)) { 
        $this->connect(); 
     }
     return $this->database;
  }

}
/*class DatabaseManager
{
    private static $instance;
    private $db_connection;

    public function initDBConnection() {
          self::getInstance()->db_connection = mysqli_connect("192.168.1.20", "group5", "grp5@leg", "group5") or die ("Unable to connect!");
		  if(mysqli_connect_errno()){
				printf("Connect failed: %s\n",mysqli_connect_errno());
				exit();
			}
    }

    public static function getInstance()
    {
            if (self::$instance == null) {
                    $className = __CLASS__;
                    self::$instance = new $className();
            }
            return self::$instance;
    }

    public static function getDB() 
    {
         return self::getInstance()->db_connection;
    }

}*/
?>